package cn.quang.search.toolkit.component.items.impl;

import cn.quang.search.toolkit.component.AbstractSearchItem;
import cn.quang.search.toolkit.component.constants.Constants;
import cn.quang.search.toolkit.enums.DataSourceTypeEnum;
import cn.quang.search.toolkit.enums.SearchOperator;
import cn.quang.search.toolkit.provider.entity.QuerySlice;

import java.util.Collections;

/**
 * yinsusha
 */
public class NotNullSearchItem extends AbstractSearchItem {
    public <T> NotNullSearchItem(DataSourceTypeEnum dsType, String col, SearchOperator operator) {
        super(dsType, col, operator);
    }

    @Override
    public QuerySlice getQuerySlice() {
        String sqlTemplate;
        if(dsType == DataSourceTypeEnum.ES) {
            sqlTemplate = String.format("%s%s%s%s", Constants.FIELD, " is not missing and ", Constants.FIELD, " is not null");
        } else if(dsType == DataSourceTypeEnum.MYSQL) {
            sqlTemplate = String.format("%s%s", Constants.FIELD, " is not null");
        } else {
            throw new IllegalArgumentException("不支持的数据源！");
        }
        return QuerySlice.of(
                sqlTemplate,
                Collections.emptyList()
        );
    }
}
